package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;
import com.hl.sfzy.entity.SysArticleSort;
import com.hl.sfzy.entity.SysFmSort;
import com.hl.sfzy.service.SysArticleSortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: sfzy
 * @ClassName SysArticleSortController
 * @description:
 * @author: lyp
 * @create: 2024-07-13 15:26
 * @Version 1.0
 **/
@RestController
public class SysArticleSortController {
    @Autowired
    private SysArticleSortService sysArticleSortService;

    //新增
    @PostMapping("/sysArticleSort")
    public Result add(@RequestBody SysArticleSort sysArticleSort) {
        int num = sysArticleSortService.add(sysArticleSort);
        return num > 0 ? Result.success() : Result.error();
    }

    //删除
    @DeleteMapping("/sysArticleSort/{id}")
    public Result remove(@PathVariable("id") Integer id) {
        int num = sysArticleSortService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/sysArticleSort")
    public Result removeBatch(Integer[] ids) {
        int num = sysArticleSortService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }

    //修改
    @PutMapping("/sysArticleSort")
    public Result edit(@RequestBody SysArticleSort sysArticleSort) {
        int num = sysArticleSortService.edit(sysArticleSort);
        return num > 0 ? Result.success() : Result.error();
    }

    //根据id查询
    @GetMapping("/sysArticleSort/{id}")
    public Result findById(@PathVariable("id") Integer id) {
        SysArticleSort sysArticleSort = sysArticleSortService.findById(id);
        return Result.success(sysArticleSort);
    }

    //查询所有
    @GetMapping("/sysArticleSort")
    public Result findAll(SysArticleSort sysArticleSort) {
        List<SysArticleSort> list = sysArticleSortService.find(sysArticleSort);
        return Result.success(list);
    }

    //分页查询
    @GetMapping("/sysArticleSort/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysArticleSort sysArticleSort) {
        Map<String, Object> map = sysArticleSortService.findPage(pageNum, pageSize, sysArticleSort);

        return Result.success(map);
    }
}

